package com.runa.persistence;


import java.util.ArrayList;
import java.util.List;

/**
 * 2022/7/7 11:39
 * zhangYB
 */
public class StringUtil {


    public static String valueOf(Boolean b) {
        return b ? "true" : "false";
    }

    public static String omit(String s) {
        return omit(s, 5000);
    }

    public static String omit(String s, Integer maxLength) {
        if (StringUtil.isBlank(s)) {
            return s;
        }
        if (s.length() > maxLength) {
            s = s.substring(0, maxLength - 6).concat("......");
        }
        return s;
    }

    public static List<String> split(String s, String sp) {
        List<String> result = new ArrayList<>();
        if (isBlank(s)) {
            return result;
        }
        String[] splits = s.split(sp);
        for (String split : splits) {
            if (isNotBlank(split)) {
                result.add(split);
            }
        }
        return result;
    }


    public static boolean isNotBlank(CharSequence cs) {
        return !isBlank(cs);
    }

    public static boolean isBlank(CharSequence cs) {
        int strLen = length(cs);
        if (strLen != 0) {
            for (int i = 0; i < strLen; ++i) {
                if (!Character.isWhitespace(cs.charAt(i))) {
                    return false;
                }
            }

        }
        return true;
    }

    public static int length(CharSequence cs) {
        return cs == null ? 0 : cs.length();
    }




}
